package v4

// 打折优惠示例

type onSalePlan interface {
	GetPrice(oldPrice float64) float64
}

// 没有打折优惠
type noPlan struct {
}

func (n *noPlan) GetPrice(oldPrice float64) float64 {
	return oldPrice
}

// 立减优惠
type knockPlan struct {
	// 立减金额
	amount float64
}

func (k *knockPlan) GetPrice(oldPrice float64) float64 {
	return oldPrice - k.amount
}

// 打折优惠
type discountPlan struct {
	previousPlan onSalePlan
	discount     int
}

func NewDiscountPlanV1(discount int) *discountPlan {
	return &discountPlan{
		previousPlan: &noPlan{},
		discount:     discount,
	}
}

func NewDiscountPlanV2(plan onSalePlan, discount int) *discountPlan {
	return &discountPlan{
		previousPlan: plan,
		discount:     discount,
	}
}

func (d *discountPlan) GetPrice(oldPrice float64) float64 {
	return d.previousPlan.GetPrice(oldPrice) * float64(d.discount) / 10
}
